package org.groovymud.login;

import org.apache.commons.net.telnet.TelnetInputListener;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.Buffer;

import static org.junit.Assert.fail;

public class StubTelnetInputListener implements TelnetInputListener {
    private final BufferedInputStream inputStream;
    private final StringBuilder screenContents = new StringBuilder();

    public StubTelnetInputListener(InputStream inputStream){
        this.inputStream = new BufferedInputStream(inputStream);
    }
    public void telnetInputAvailable() {
        try {
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes);
            screenContents.append(new String(bytes));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String getScreenContents() {
        return screenContents.toString();
    }
}
